Borland Online And The Cobb Group Present:


September, 1995 - Vol. 2 No. 9

Running multiple versions of Borland C++ using WinRun

Recently, you may have begun using Borland C++ 4.51. However, if you have some existing projects that you created under version 4.02, you may have decided to install version 4.51 to a separate directory to keep the two versions isolated. (This setup also allows you to switch back to version 4.02 should you find any incompatibilities in the new version.)

However, all versions of Borland C++ since 4.0 use a private profile file that's named BCW.INI and that's stored in the \WINDOWS directory. If you tried to use either version of the program, it would write its default settings file to the BCW.INI file, including the configuration of the Integrated Development Environment (IDE) desktop.

To solve this problem, you need to create a simple batch file that copies an appropriate version of BCW.INI into the \WINDOWS directory, run the corresponding version of Borland C++, and then back up the BCW.INI file when you exit.

Prior to the release of version 4.5, this solution wouldn't have been possible. Until then, you couldn't launch a Windows application from a DOS batch file without buying a third-party program. Even then, you typically wouldn't have been able to force the batch file to pause until the Windows application exited. However, WinRun does away with this limitation. In this article, we'll show how you can use this Windows utility, which ships with Borland C++ 4.5 and later versions, to launch Windows applications such as Borland C++ from a DOS batch file.

Out to launch

In order to launch different versions of Borland C++ 4.x while keeping their INI files separate, you'll need three things: a utility for launching Windows programs from a command line or batch file, the batch file itself, and a Program Information File (PIF). Let's take a look at each of these elements separately.

Launching Windows programs from DOS

Typically, if you try to run a Windows application from DOS, the operating system will execute a special segment of DOS code that appears at the beginning of the Windows EXE file. This DOS code usually just informs the users that they need to run the program under Windows. (See the March 1995 article Windows programming - Creating a Windows program stub for more information.) To launch a Windows program from a DOS command line or batch file, you'll need to use a special utility to notify Windows that it should launch a program.

Fortunately, Borland C++ 4.5 ships with a utility program named WinRun that performs this special function. If you set up WinRun correctly, it will automatically detect when you try to run a Windows program from DOS and will then launch the program.

In addition, you can configure WinRun to suspend the execution of the DOS command line or batch file until the Windows application exits. Since WinRun doesn't execute programs this way by default, you must change its command-line parameters to alter its behavior. To learn more about using WinRun this way, see WinRun's Command-Line Options below.

Batch file requirements

At the beginning of this article, we told you about the BCW.INI file and mentioned that all versions of Borland C++ since 4.0 use this file to store configuration information. If you want to be able to use more than one version of Borland C++ 4.x on the same system, you'll need to maintain a separate BCW.INI file for each version in order to ensure that one version doesn't try to use the header files or libraries that shipped with another version. (The compiler determines the correct files to use based on the directory paths in the configuration and project files.)

One approach to maintaining a BCW.INI file for a given version of Borland C++ is to create a simple batch file that takes the following actions:

You should note that this technique assumes you've placed a BCW.INI file in each appropriate \BIN directory before you try running a particular version.

Setting the PIF

Since you'll probably want to launch each version of Borland C++ the same way that you did before, you need to create program items in the appropriate Program Manager groups for each batch file. However, instead of simply launching the batch file directly from a Program Manager icon, you should create a PIF file for each batch file.

A PIF file allows you to specify how Windows will execute a DOS command line or batch file. For the batch file that you'll create to launch Borland C++, you'll specify that Windows should run a batch file in a window, process it in the background, and then automatically close the window when the batch file exits. Doing so will help to reduce the clutter of extra open windows on your screen.

Finally, you'll need to create a program item in Program Manager to launch the batch file. (To use the settings in the PIF file that we just described, you'll actually place the PIF file's name in the program item's command line.) When you create the program item, you'll configure it to launch the batch file in a minimized window, once again to reduce onscreen clutter.

A batchin' example

Now let's create a batch file to launch Borland C++ 4.5. (You can use this same technique to create a batch file for one of the other 4.x versions.) To begin, open a new text file in a text editor such as Notepad.

When the editing window appears, enter the following commands:

copy \bc45\bin\bcw.ini \windows\bcw.ini
\bc45\bin\wr -w \bc45\bin\bcw
copy \windows\bcw.ini \bc45\bin\bcw.ini

When you finish, save the file as BC45.BAT.

Next, double-click the MS-DOS Prompt icon in Program Manager's Main group to open a DOS command line. At the command line, enter the command

copy \windows\bcw.ini \bc45\bin\bcw.ini

to create a private BCW.INI file for the batch file to use. Type exit to close the DOS command line.

Double-click the PIF Editor icon in Program Manager's Main group. When the PIF Editor main window appears, enter C:\WINDOWS\BC45.BAT in the Program Filename entry field, enter Borland C++ 4.5 Batch in the Window Title entry field, select the Windowed radio button in the Display Usage group, and then select the Background check box in the Execution group.

When you finish, the PIF Editor window should resemble the one shown in Figure A. Choose Save from the File menu. In the Save As dialog box, enter bc45.pif in the File Name entry field and click OK. Choose Exit from the File menu to close the PIF Editor.


Figure A - You'll create a PIF for the Borland C++ 4.5 batch file using the PIF Editor.

Open the Borland C++ 4.5 program group in Program Manager, and then choose New... from the File menu. In the New Program Object dialog box, select the Program Item radio button and click OK.

In the Program Item Properties dialog box, enter Borland C++ 4.5 Batch in the Description entry field, enter \windows\bc45.pif in the Command Line entry field, enter \windows in the Working Directory entry field, and select the Run Minimized check box. When you finish, confirm that the dialog box matches the one shown in Figure B, and click OK.


Figure B - You'll create a new program item that you can use to launch the Borland C++ 4.5 batch file from Program Manager.

Now, you can double-click the Borland C++ 4.5 Batch icon to launch version 4.5 and automatically save the BCW.INI file for this version. If you use the same technique to create a batch file for other 4.x versions, each one will maintain its own BCW.INI file without affecting the other versions.

Conclusion

In most cases, newer versions of Borland C++ have retained full compatibility with previous versions. However, if you must maintain projects that were written using version 4.0 or 4.02, you may want to keep those versions on your system to ensure full compatibility. By taking advantage of WinRun's ability to launch Windows programs from a batch file, as we've shown here, you'll be able to maintain separate configuration files for multiple versions of Borland C++ on the same PC.

Return to the Borland C++ Developer's Journal index

Subscribe to the Borland C++ Developer's Journal


Copyright (c) 1996 The Cobb Group, a division of Ziff-Davis Publishing Company. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis Publishing Company is prohibited. The Cobb Group and The Cobb Group logo are trademarks of Ziff-Davis Publishing Company.